/**
 * 消息服务(短信|语音)messageList.js
 * 版本号： v1.0.0
 */
$(function(){
    $("#messageDg").datagrid({
        fit:true,
        fitColumns: true,
        method: "POST",
        rownumbers: true,
        singleSelect:true,
        striped:true,
        pagination: true,
        border:false,
        pageSize:25,
        pageList:[25],
        url: CONTEXT_PATH + '/message/messageList.do',
        idField: 'id',
        frozenColumns:[[
            {field:'id',checkbox:true}
        ]],
        columns: [
            [
                {field: 'sendType', title: '消息类型', width: 80, align: 'center', fixed: true, formatter:function(val){
                    if(val == 'SMS'){
                        return "<span style='color: green; font-weight: bold'; >短信</span>";
                    }
                    if(val == 'PUSH'){
                        return "<span style='color: red; font-weight: bold'>推送</span>";
                    }
                    if(val == 'VIDO'){
                        return "<span style='color: #0000ff; font-weight: bold'>语音</span>";
                    }
                }},
                {field: 'sendWay', title: '发送方式', width: 80, align: 'center', fixed: true},
                {field: 'phone',  title: '手机号码', width: 90, align: 'center', fixed: true},
                {field: 'content',  title: '发送内容', width: 700},
                {field: 'status', title: '发送状态', width: 70, align: 'center', fixed: true,formatter:function(val){
                    if(val == 0) return "<span style='color: red; font-weight: bold'>失败</span>";
                    if(val == 1) return "<span style='color: green; font-weight: bold'>成功</span>";

                }},
                {field: 'createDate', title: '发送时间', width: 135, align: 'center',fixed: true},
                {field: 'remark',  title: '消息备注', width: 150, fixed: true}
            ]
        ],
        onLoadSuccess:function(data){
            if(data.rows.length > 0){
                $("#messageDg").datagrid("selectRow", 0);
            }
        }
    });

    //定义可操作按钮
    $("#messageMenu").datagrid({
        border:false,
        fit:true,
        toolbar:[{
            id:"messageQuery",
            text:"查询消息",
            iconCls:"icon-custom-search",
            handler:function(){
                message_findList();
            }
        },"-",{
            id:"messageRefresh",
            text:"刷新消息",
            iconCls:"icon-custom-detail",
            handler:function(){
                message_refresh();
            }
        },"-"
        ]
    });

});





/**
 * 刷新消息
 */
function message_refresh(){
    $("#messageDg").datagrid("reload",{});
    $("#messageDg").datagrid("clearSelections");
}


/**
 * 查询消息
 */
function message_findList(){
    $("#messageQuery_dialog").dialog({
        title: '查询消息',
        width: 380,
        modal: true,
        closed: true,
        height: 180,
        iconCls:"icon-custom-search",
        buttons:[{
            text:"查询",
            iconCls:"icon-role-state-ok",
            handler:function(){
                $("#messageDg").datagrid("reload",{
                        sendType:$("#sendType").combobox("getValue"),
                        sendWay:$("#sendWay").combobox("getValue"),
                        phone:$("#phone").val()
                    }
                );
                $("#messageDg").datagrid("clearSelections");
                $('#messageQuery_dialog').dialog('close');
            }
        },{
            text:"取消",
            iconCls:"icon-role-state-no",
            handler:function(){
                $('#messageQuery_dialog').dialog('close');
            }
        }]
    });
    $("#messageQuery_dialog").dialog("move",{left:450,top:100});
    $("#messageQuery_dialog").dialog('open');
}